<?php
header("content-type:text/html;charset=utf-8");
$mysqli = new mysqli("localhost", "root", "123", "my_test");
$mysqli->set_charset("utf8");
$query = "SELECT * FROM users";
$res = $mysqli->query($query);
if ($res && $res->num_rows) {
    while ($row = $res->fetch_assoc()) {
        $rows[] = $row;
    }
} else {
    echo "暂无用户";
}

?>

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户列表</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            text-align: center;
            font: 12px/150% Arial, Verdana, "\5b8b\4f53";
            color: #666;
            background: #fff
        }

        p {
            text-align: right;
            width: 80%;
            margin: 10px auto;
        }

        a {
            color: #666;
            text-decoration: none;
        }

        table {
            border: 1px solid #ccc;
            width: 80%;
            margin: 0 auto;
            border-collapse: collapse;
        }

        tr {
            line-height: 35px;
        }

        tr:first-child {
            background: #ccc;
            border-bottom: 1px solid #ccc;
        }

        td {
            text-align: center;
        }

        td a {
            display: inline-block;
            margin: 0 5px;
        }

        a:hover {
            color: #333;
            text-decoration: underline;
        }
    </style>
</head>
<body>
<h2>用户列表</h2>
<p><a href="user_add.php">添加用户</a></p>
<table>
    <tr>
        <td>编号</td>
        <td>用户名</td>
        <td>年龄</td>
        <td>操作</td>
    </tr>
    <?php
    $i = 0;
    foreach ($rows as $row) { ?>
        <tr>
            <td><?php echo ++$i; ?></td>
            <td><?php echo $row['username'] ?></td>
            <td><?php echo $row['age'] ?></td>
            <td><a href="user_edit.php?action=edit&id=<?php echo $row['id']; ?>">编辑</a>
                <a href="user_response.php?action=del&id=<?php echo $row['id']; ?>">删除</a>
            </td>
        </tr>
        <?php
    }
    ?>




</table>
</body>
</html>
